package com.wyj.user.feign;

import com.wyj.code.api.ICodeApi;
import com.wyj.code.entity.dto.CodeDTO;
import com.wyj.response.ApiResult;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;

/**
 * TODO:
 *
 * @author wuyijie
 * @date 2022/2/10 6:56 PM
 */
@FeignClient(value = "code-service", path = "/code", fallback = CodeFeign.CodeFeignFallbackFactory.class)
public interface CodeFeign extends ICodeApi {

    @Component
    class CodeFeignFallbackFactory implements FallbackFactory<CodeFeign> {
        /**
         * Returns an instance of the fallback appropriate for the given cause.
         *
         * @param cause cause of an exception.
         * @return fallback
         */
        @Override
        public CodeFeign create(Throwable cause) {
            return new CodeFeign() {
                @Override
                public ApiResult<CodeDTO> createWithIdentification(String identification) {
                    return ApiResult.busy();
                }

                @Override
                public ApiResult<CodeDTO> code(String code, String identification) {
                    return ApiResult.busy();
                }
            };
        }
    }
}
